package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 牛毅
 * @version 1.0
 * @date 2025/7/21
 * @description TODO
 */
@RestController
@RequestMapping("/prod/type")
public class TypeController {
    @Autowired
    TbTypeService tbTypeService;

    /** 
     * @description: 获取类型列表 
     * @param:  
     * @return: com.bwie.utils.R 
     * @author 牛毅
     * @date: 2025/7/21 15:32
     */ 
    @PostMapping("/getTypeTree")
    public R getTypeTree(@RequestBody PageInfoVo pageInfoVo){
        return tbTypeService.getTypeTree(pageInfoVo);
    }
    /**
     * @description: 图片上传
     * @param: null
     * @return:
     * @author 牛毅
     * @date: 2025/7/21 17:20
     */
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file")MultipartFile file){
        return tbTypeService.uploadFile(file);
    }

    /**
     * @description: 添加类型
     * @param: file
     * @return: com.bwie.utils.R
     * @author 牛毅
     * @date: 2025/7/21 17:29
     */
    @PostMapping("/addType")
    public R addType(@RequestBody @Validated TbType tbType, BindingResult result){
        return tbTypeService.addType(tbType,result);
    }
    /**
     * @description: 树形
     * @param: file
     * @return: com.bwie.utils.R
     * @author 牛毅
     * @date: 2025/7/21 17:29
     */
    @PostMapping("/selectType")
    public R selectType(){
        return tbTypeService.selectType();
    }
}
